import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lcapp/api/interface/popover.dart';
import 'package:lcapp/data/popover_data_entity.dart';
import 'package:lcapp/model/banner/banner_operate.dart';
import 'package:lcapp/model/popover/popover.dart';
import 'package:lcapp/routes/route.dart';
import 'package:lcapp/widget/asr_cache_image.dart';


class PopMenuDialog extends StatefulWidget {
  final PopoverDataEntity? entity;
  const PopMenuDialog({Key? key, this.entity}) : super(key: key);

  @override
  _PopMenuDialogState createState() => _PopMenuDialogState();
}

class _PopMenuDialogState extends State<PopMenuDialog> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    setViews();
  }
  void setViews() async{
    PopoverAPI.readPopover(widget.entity!.id!);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              width: 652.w,
              constraints: BoxConstraints(
                maxHeight: 900.w
              ),
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    GestureDetector(
                      onTap: (){
                        SmartDialog.dismiss();
                        BannerOperate.bannerGoPage(widget.entity!,callBack: (){
                          PopoverManager.getPops();
                        });
                      },
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(20.w),
                        child: Container(
                          color: Colors.white,
                          child: ASRCacheImage(
                            image: widget.entity!.image!,
                            width: 652.w,
                            fit: BoxFit.fitWidth,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            GestureDetector(
              onTap: () {
                SmartDialog.dismiss();
                PopoverManager.getPops();
              },
              child: Container(
                margin: EdgeInsets.only(top: 40),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(40)
                ),
                child: Icon(Icons.clear,color: Colors.black,size: 30,),
              ),
            )
          ]),
    );
  }
}
